package com.wuzhishan.news.listen;

import com.wuzhishan.news.mapper.groupMapper;
import com.wuzhishan.news.pojo.BlogGroup;
import com.wuzhishan.news.utils.SpringApplicationContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.DependsOn;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;

@WebListener
public class GroupListener implements ServletContextListener {

    @Autowired
    private groupMapper mapper;
    /**
     * 整个应用程序创建时初始化动作
     * @param servletContextEvent
     */
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        List<BlogGroup> groupList = mapper.getAll();
        servletContextEvent.getServletContext().setAttribute("groupList",groupList);
    }
    /**
     * 整个应用程序销毁时动作
     * @param servletContextEvent
     */

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
